What is @changesets/parse?
@changesets/parse is a utility for parsing changeset files in a JavaScript/TypeScript project. It helps in reading and interpreting changeset files, which are used to manage versioning and changelogs in a project.
What are @changesets/parse's main functionalities?
Parsing a Changeset File
This feature allows you to parse a changeset file content and get a structured representation of the changeset. The `parseChangeset` function takes the raw content of a changeset file and returns an object with the parsed information.
const { parseChangeset } = require('@changesets/parse');
const changesetContent = `---
"package-a": patch
"package-b": minor
---
Some description of the changes.`;
const parsedChangeset = parseChangeset(changesetContent);
console.log(parsedChangeset);
Handling Invalid Changeset Content
This feature demonstrates how to handle errors when parsing invalid changeset content. The `parseChangeset` function will throw an error if the content is not valid, which can be caught and handled appropriately.
const { parseChangeset } = require('@changesets/parse');
try {
const invalidChangesetContent = `---
"package-a": unknown
---
Invalid changeset content.`;
const parsedChangeset = parseChangeset(invalidChangesetContent);
} catch (error) {
console.error('Failed to parse changeset:', error.message);
}
Other packages similar to @changesets/parse
conventional-changelog
The `conventional-changelog` package is used to generate changelogs based on conventional commit messages. It provides a way to automate the process of creating changelogs and managing versioning. Unlike @changesets/parse, which focuses on parsing changeset files, `conventional-changelog` is more about generating changelogs from commit messages.
standard-version
The `standard-version` package is a utility for versioning and changelog generation based on conventional commit messages. It automates the process of version bumping, changelog generation, and git tagging. While `standard-version` focuses on the entire release process, @changesets/parse is specifically for parsing changeset files.
lerna
Lerna is a tool for managing JavaScript projects with multiple packages. It optimizes the workflow around managing multi-package repositories. Lerna includes features for versioning and publishing packages, which can be compared to the functionality provided by changesets. However, Lerna is a more comprehensive tool for monorepo management, whereas @changesets/parse is focused on parsing changeset files.
@changesets/parse
Parses a changeset from its written format to a data object.
import parse from "@changesets/parse";
const changeset = `---
"@changesets/something": minor
"@changesets/something-else": patch
---
A description of a minor change`;
const parsedChangeset = parse(changeset);
For example, it can convert:
---
"@changesets/something": minor
"@changesets/something-else": patch
---
A description of a minor change
to
{
"summary": "A description of a minor change",
"releases": [
{ "name": "@changesets/something", "type": "minor" },
{ "name": "@changesets/something-else", "type": "patch" }
]
}
Note that this is not quite a complete Changeset for most tools as it lacks an id
.
For written changesets, the id is normally given as the file name, which parse is not aware of.